﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VRacer.Packets
{
    public class NewPlayerPacket: PlayerPacket
    {
        private int _version;
        private string _title = "";

        public NewPlayerPacket()
            : base(PacketType.NewPlayer)
        {
            this.Length += 8;
        }

        public NewPlayerPacket(PlayerBase player)
            :this()
        {
            this.ID = player.ID;
            this.Title = player.Title;
            this.Version = 1;
        }

        public override int Length
        {
            get
            {
                return base.Length + UTF8Encoding.UTF8.GetByteCount(_title);
            }
        }

        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }

        public int Version
        {
            get { return _version; }
            set { _version = value; }
        }

        public override void Write(System.IO.BinaryWriter writer)
        {
            base.Write(writer);

            writer.Write(_id);
            writer.Write(_title);
            writer.Write(_version);
        }

        public override void Read(System.IO.BinaryReader reader)
        {
            base.Read(reader);

            _id = reader.ReadInt32();
            _title = reader.ReadString();
            _version = reader.ReadInt32();
        }
    }
}
